package com.zgz.underwrite.util;


import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
 * 
 * @author zgz 
 * 时间：2011-7-4
 * 功能描述：hibernate辅助类
 * 通过configuration拿到SessionFactory
 */
public class HibernateUtil {

	
	private static final SessionFactory sessionFactory;

	static {
		try {
			sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();

		} catch (HibernateException ex) {
			throw new RuntimeException(
					"创建SessionFactory出错: " + ex.getMessage(), ex);
		}
	}
	
	public static SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	public static Session getSession(){
		return getSessionFactory().getCurrentSession();
	}
	
//     public static void main(String []args){
//    	 HibernateUtil.getSessionFactory();
//    	 getSession().beginTransaction();
//    	 Product product = new Product();
// 		 product.setSProductCde("465464");
// 		 product.setSProductName("asdfasdfasdf");
// 		 getSession().save(product);
// 		 getSession().getTransaction().commit();
//    	 
//     }
}
